package cn.iocoder.yudao.module.agent.controller.app.brokeragerecord;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.agent.controller.admin.brokeragerecord.vo.AgentBrokerageRecordPageReqVO;
import cn.iocoder.yudao.module.agent.controller.admin.brokeragerecord.vo.AgentBrokerageRecordRespVO;
import cn.iocoder.yudao.module.agent.convert.brokeragerecord.AgentBrokerageRecordConvert;
import cn.iocoder.yudao.module.agent.dal.dataobject.brokeragerecord.AgentBrokerageRecordDO;
import cn.iocoder.yudao.module.agent.service.brokeragerecord.AgentBrokerageRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "APP - 佣金记录")
@RestController
@RequestMapping("/agent/brokerage-record")
@Validated
public class AppAgentBrokerageRecordController {

    @Resource
    private AgentBrokerageRecordService brokerageRecordService;

    @GetMapping("/page")
    @Operation(summary = "获得代理人佣金记录分页")
    public CommonResult<PageResult<AgentBrokerageRecordRespVO>> getBrokerageRecordPage(@Valid AgentBrokerageRecordPageReqVO pageVO) {
        pageVO.setAgentUserId(getLoginUserId());

        PageResult<AgentBrokerageRecordDO> pageResult = brokerageRecordService.getBrokerageRecordPage(pageVO);
        return success(AgentBrokerageRecordConvert.INSTANCE.convertPage(pageResult));
    }
}
